/*   1:    */ package org.intellij.plugins.relaxNG.config;
/*   2:    */ 
/*   3:    */

import com.intellij.openapi.actionSystem.LangDataKeys;
import com.intellij.openapi.editor.HectorComponentPanel;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.ui.ComponentWithBrowseButton;
import com.intellij.openapi.ui.ComponentWithBrowseButton.BrowseFolderActionListener;
import com.intellij.openapi.ui.TextComponentAccessor;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;
import org.intellij.plugins.relaxNG.compact.RncFileType;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */
/*  16:    */
/*  17:    */
/*  18:    */
/*  19:    */
/*  20:    */
/*  21:    */
/*  22:    */
/*  23:    */
/*  24:    */
/*  25:    */
/*  26:    */ 
/*  27:    */ class NoNamespaceConfigPanel
/*  28:    */   extends HectorComponentPanel
/*  29:    */ {
/*  30:    */   private final NoNamespaceConfig a;
/*  31:    */   private final PsiFile b;
/*  32:    */   private final String c;
/*  33:    */   private TextFieldWithBrowseButton d;
/*  34:    */   private JPanel e;
/*  35:    */   private boolean f;
/*  36:    */   
/*  37:    */   NoNamespaceConfigPanel(NoNamespaceConfig paramNoNamespaceConfig, PsiFile paramPsiFile)
/*  38:    */   {
/*  39: 55 */     this.a = paramNoNamespaceConfig;
/*  40: 56 */     this.b = paramPsiFile;
/*  41: 57 */     b();this.c = this.a.getMapping(paramPsiFile);
/*  42:    */     
/*  43: 59 */     FileChooserDescriptor local1 = new FileChooserDescriptor(true, false, false, false, false, false)
/*  44:    */     {
/*  45:    */       public boolean isFileSelectable(VirtualFile paramAnonymousVirtualFile)
/*  46:    */       {
/*  47: 61 */         boolean bool = super.isFileSelectable(paramAnonymousVirtualFile);
/*  48: 62 */         if (bool)
/*  49:    */         {
/*  50: 63 */           FileType localFileType = paramAnonymousVirtualFile.getFileType();
/*  51: 64 */           if (localFileType != StdFileTypes.XML) {
/*  52: 65 */             return localFileType == RncFileType.getInstance();
/*  53:    */           }
/*  54:    */         }
/*  55: 68 */         return bool;
/*  56:    */       }
/*  57: 71 */     };
/*  58: 72 */     Project localProject = paramPsiFile.getProject();
/*  59: 73 */     VirtualFile localVirtualFile = paramPsiFile.getVirtualFile();
/*  60: 74 */     if (localVirtualFile != null)
/*  61:    */     {
/*  62: 75 */       localObject = ProjectRootManager.getInstance(localProject).getFileIndex().getModuleForFile(localVirtualFile);
/*  63: 76 */       local1.putUserData(LangDataKeys.MODULE_CONTEXT, localObject);
/*  64:    */     }
/*  65: 81 */     Object localObject = new ComponentWithBrowseButton.BrowseFolderActionListener("Select Schema", "Select a RELAX-NG file to associate with the document", this.d, localProject, local1, TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT)
/*  66:    */     {
/*  67:    */       public void actionPerformed(ActionEvent paramAnonymousActionEvent)
/*  68:    */       {
/*  69: 85 */         NoNamespaceConfigPanel.this.f = true;
/*  70:    */         try
/*  71:    */         {
/*  72: 87 */           super.actionPerformed(paramAnonymousActionEvent);
/*  73:    */         }
/*  74:    */         finally
/*  75:    */         {
/*  76: 89 */           NoNamespaceConfigPanel.this.f = false;
/*  77:    */         }
/*  78:    */       }
/*  79: 93 */     };
/*  80: 94 */     this.d.addActionListener((ActionListener)localObject);
/*  81:    */   }
/*  82:    */   
/*  83:    */   public boolean canClose()
/*  84:    */   {
/*  85: 98 */     return (super.canClose()) && (!this.f);
/*  86:    */   }
/*  87:    */   
/*  88:    */   public JComponent createComponent()
/*  89:    */   {
/*  90:102 */     return this.e;
/*  91:    */   }
/*  92:    */   
/*  93:    */   public boolean isModified()
/*  94:    */   {
/*  95:106 */     String str1 = this.d.getText();
/*  96:107 */     String str2 = this.c != null ? this.c : "";
/*  97:108 */     return !str1.equals(str2);
/*  98:    */   }
/*  99:    */   
/* 100:    */   public void apply()
/* 101:    */     throws ConfigurationException
/* 102:    */   {
/* 103:112 */     String str = a();
/* 104:113 */     if (str != null) {
/* 105:114 */       this.a.setMapping(this.b, str);
/* 106:    */     } else {
/* 107:116 */       this.a.setMapping(this.b, null);
/* 108:    */     }
/* 109:    */   }
/* 110:    */   
/* 111:    */   private String a()
/* 112:    */   {
/* 113:121 */     String str = this.d.getText().trim();
/* 114:122 */     return str.length() > 0 ? VfsUtil.pathToUrl(str.replace(File.separatorChar, '/')) : null;
/* 115:    */   }
/* 116:    */   
/* 117:    */   public void reset()
/* 118:    */   {
/* 119:126 */     this.d.setText(this.c != null ? VfsUtil.urlToPath(this.c).replace('/', File.separatorChar) : "");
/* 120:    */   }
/* 121:    */   
/* 122:    */   public void disposeUIResources() {}
/* 123:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.intellij.plugins.relaxNG.config.NoNamespaceConfigPanel

 * JD-Core Version:    0.7.0.1

 */